package com.sharif.cn.local.subscriber;

import com.sharif.cn.Subscribe;
import com.sharif.cn.local.publish.reactive.BusinessSubscriber;
import com.sharif.cn.local.publish.reactive.DecoratingSubscriber;
import com.sharif.cn.local.publish.reactive.SimplePublisher;
import com.sharif.cn.local.publish.reactive.SubscriptionAdapter;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import java.io.IOException;
import java.util.function.Consumer;

public class LocalReactiveSubscriber {

    SimplePublisher simplePublisher;

    Consumer<Subscribe> consumer;

    public LocalReactiveSubscriber() throws IOException, InterruptedException {
        BusinessSubscriber businessSubscriber = new BusinessSubscriber(10);
        DecoratingSubscriber decoratingSubscriber = new DecoratingSubscriber(businessSubscriber);
        decoratingSubscriber.setMaxRequest(10);
        SubscriptionAdapter subscriptionAdapter = new SubscriptionAdapter(decoratingSubscriber);
        decoratingSubscriber.onSubscribe(subscriptionAdapter);
        simplePublisher = new SimplePublisher();
        simplePublisher.subscribe(new Subscriber() {
            @Override
            public void onSubscribe(Subscription s) {

            }

            @Override
            public void onNext(Object o) {

            }

            @Override
            public void onError(Throwable t) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    public void publish(Object object)
    {
        simplePublisher.publish(object);
    }
}
